package cn.cena._05topics;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Pruducer {

    // 交换机名称
    public static final String NAME_EXCHANGE_TOPICS = "NAME_EXCHANGE_TOPICS";

    public static void main(String[] args) throws IOException, TimeoutException {
        // 获取连接
        ConnectionFactory factory = new ConnectionFactory();
        Connection connection = factory.newConnection();
        // 获取通道
        Channel channel = connection.createChannel();

        // 设置交换机
        channel.exchangeDeclare(NAME_EXCHANGE_TOPICS, BuiltinExchangeType.TOPIC);

        // 发送消息
        // 参数1：交换机名 参数2：routingkey 参数三：持久化 参数4：消息内容
        channel.basicPublish(NAME_EXCHANGE_TOPICS,
                "info",
                MessageProperties.PERSISTENT_TEXT_PLAIN,
                "诈骗短信".getBytes());

        channel.close();
        connection.close();
    }
}
